
package com.kirk.cts.ui.view.navigator;

import com.kirk.cts.core.loader.LanguageLoader;
import com.kirk.cts.ui.widget.CurtainPane;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;


/**
 *  <p> Navigator.java </p>
 *
 * @Author      kirkliu
 * @Date        2020-09-01 23:02
 * @version     1.0.0
 * @Description 导航
 */
@Component("navigator")
public class Navigator {

    private JPanel cutainPane;
    private CurtainPane cp;

    public JPanel getCurtainPanelView() {
        if (cutainPane == null) {
            cutainPane = new JPanel(new BorderLayout());
            cp = getCurtainPane();
            //show the first layer.
            cutainPane.add(cp, BorderLayout.CENTER);

            JCheckBox box = getAnimationCheckBox(cp);
            cutainPane.add(box, BorderLayout.SOUTH);
        }

        return cutainPane;
    }

    /**
     * 加载插件导航栏
     */
    public void loadPluginNavigator(List<NavigatorItem> navigatorList) {
        if (CollectionUtils.isNotEmpty(navigatorList)) {
            for (NavigatorItem item : navigatorList) {
                cp.addPane(item.getTitle(), item.getIcon(), item.getComp());
            }
        }
        cp.setSelectedPane(0);
    }

    private CurtainPane getCurtainPane() {
        CurtainPane fp = new CurtainPane();
        fp.setAnimated(true);
        return fp;
    }

    private JCheckBox getAnimationCheckBox(final CurtainPane cp) {
        final JCheckBox box = new JCheckBox(LanguageLoader.getString("CrawlerMainFrame.enableAnimation"));
        box.setSelected(true);
        box.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cp.setAnimated(box.isSelected());
            }
        });
        return box;
    }

}
